/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assisisw.smartcal.persistencesubsystem;

import assisisw.smartcal.entitysubsystem.Notification;
import assisisw.smartcal.utilities.Configuration;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

/**
 *
 * @author Francesco
 */
@Stateless ()

public class PostgreSQLJPANotificationDAO implements INotificationDAO
{

    // Instance Fields
    
    /***/
    @PersistenceContext ( unitName = Configuration.PU_NAME , type = PersistenceContextType.TRANSACTION )
    private EntityManager entityManager ;
    
    // Instance Methods
    
    /***/
    public PostgreSQLJPANotificationDAO () {}
    
    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public void insert ( Notification notification ) 
    {
        if ( notification != null )
        {
            entityManager.persist ( notification ) ;
            entityManager.flush();
        }
        else
            throw new IllegalArgumentException () ;
    }

    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public void update ( Notification notification ) 
    {
        if ( notification != null )
        {
            entityManager.merge ( notification ) ;
            entityManager.flush () ;
        }
        else
            throw new IllegalArgumentException () ;
    }

    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public void delete ( Notification notification ) 
    {
        if ( notification != null )
        {
            entityManager.remove ( notification ) ;
            entityManager.flush();
        }
        else
            throw new IllegalArgumentException () ;
    }
    
}
